﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.DomainServices.Server;
using System.Text;

namespace Arch.DomainServices.Metadata
{
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
    public abstract class DomainMetadataProviderAttribute : DomainServiceDescriptionProviderAttribute
    {
        protected DomainMetadataProviderAttribute()
            : base(typeof(DomainMetadataProvider))
        {
        }

        public override DomainServiceDescriptionProvider CreateProvider(Type domainServiceType, DomainServiceDescriptionProvider parent)
        {
            var provider = (DomainMetadataProvider)base.CreateProvider(domainServiceType, parent);

            if (provider.IsConfigured == false)
            {
                Configure(new MetadataBuilder(provider));
                provider.IsConfigured = true;
            }

            return provider;
        }

        public abstract void Configure(MetadataBuilder builder);
    }
}
